Sort Counter by Value¶
Sample data:
{‘Math’: 81, ‘Physics’: 83, ‘Chemistry’: 87}
Expected output:
[(‘Chemistry’, 87), (‘Physics’, 83), (‘Math’, 81)]
from collections import Counter
D = {'Math': 81,
'Physics': 83,
'Chemistry': 87,
}
LOT = Counter(D)
print(LOT.most_common())
Output:
[('Chemistry', 87), ('Physics', 83), ('Math', 81)]